<?php
namespace app\admin\controller;
use app\admin\model\AuthGroupAccess;
use app\admin\model\RuleGroup;
use app\admin\model\User as UserModel;
/**
 * 权限控制 - 用户管理
 * @author Mr.li
 * @Date 2018.8.15
 *
 */
class User extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->authGroupAccess = new AuthGroupAccess();
        $this->ruleGroup = new RuleGroup();
        $this->user = new UserModel();
    }
    public function index(){
        $list = $this->authGroupAccess->getUserList();
        $this->assign("data",$list);
        return $this->fetch();
    }
    //添加管理员
    public function addUser(){
        if(request()->isPost()){
            $data = input("post.");
            $res = $this->authGroupAccess->add($data);
            return $res;
        }else{
            $list = $this->ruleGroup->getList();
            $this->assign("data",$list);
            return $this->fetch();
        }
    }
    //修改管理员
    public function editUser(){
        if(request()->isPost()){
            $data = input("post.");
            $res = $this->authGroupAccess->edit($data);
            return $res;
        }else{
            $id = input("get.id");
            $userData = $this->user->getList($id);
            $list = $this->ruleGroup->getList();
            $this->assign("data",$list);
            $this->assign("user_data",$userData);
            return $this->fetch();
        }
    }
}
